package cn.e2win.base.entity;

import java.awt.Menu;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "sys_menu")
public class SysMenu extends BaseEntity implements Comparable<SysMenu>{

	private static final long serialVersionUID = 1L;
	
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	private Integer id;

	@Column(name="title",length=128)
	private String title;
	
	@Column(name="orderMark",length=5)
	private Integer orderMark;
	
	@OneToMany(fetch=FetchType.EAGER)
	@JoinColumn(name="menuId")
	private List<SysFunction> functionList;
	
	//this field only for view, could not be in database
	@Transient
	private boolean hasItems;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Integer getOrderMark() {
		if(orderMark == null || orderMark.intValue() == 0) {
			return this.id;
		}
		return orderMark;
	}

	public void setOrderMark(Integer orderMark) {
		this.orderMark = orderMark;
	}

	public boolean isHasItems() {
		return hasItems;
	}

	public List<SysFunction> getFunctionList() {
		return functionList;
	}

	public void setFunctionList(List<SysFunction> functionList) {
		this.functionList = functionList;
	}

	public void setHasItems(boolean hasItems) {
		this.hasItems = hasItems;
	}

	@Override
	public int compareTo(SysMenu o) {
		// TODO Auto-generated method stub
		return this.getOrderMark().compareTo(o.getOrderMark());
	}


}
